EXPON
Overview
The EXPON function computes various properties of the exponential distribution, a continuous probability distribution commonly used to model the time between events in a Poisson process. This distribution is fundamental in reliability engineering, queuing theory, and survival analysis for representing waiting times, component lifetimes, and inter-arrival times.
The exponential distribution is characterized by its memoryless property: the probability of an event occurring in the next time interval is independent of how much time has already elapsed. This makes it particularly suitable for modeling processes where the probability of failure or occurrence remains constant over time.
This implementation wraps scipy.stats.expon from the SciPy library. For the standardized form, the probability density function (PDF) is defined as:
f(x) = e^{-x}
for x \geq 0. The general form incorporates loc (location/shift) and scale parameters, where scale corresponds to 1/\lambda (the inverse of the rate parameter \lambda). The generalized PDF becomes:
f(x; \text{loc}, \text{scale}) = \frac{1}{\text{scale}} \exp\left(-\frac{x - \text{loc}}{\text{scale}}\right)
The exponential distribution is a special case of the gamma distribution with shape parameter a = 1. Key statistical properties include a mean equal to scale + loc and variance equal to scale².
The function supports multiple methods: PDF (probability density), CDF (cumulative distribution), SF (survival function), ICDF (inverse CDF/quantile function), ISF (inverse survival function), and summary statistics including Mean, Median, Var, and Std.
This example function is provided as-is without any representation of accuracy.
Excel Usage
=EXPON(value, loc, scale, expon_method)
value(float, optional, default: null): Input value for pdf/cdf/sf, or probability for icdf/isf methodsloc(float, optional, default: 0): Location parameter (shift)scale(float, optional, default: 1): Scale parameter (must be > 0)expon_method(str, optional, default: “pdf”): Distribution method to compute
Returns (float): Distribution result (float), or error message string.
Examples
Example 1: PDF at x=2 with standard exponential
Inputs:
| value | loc | scale | expon_method |
|---|---|---|---|
| 2 | 0 | 1 |
Excel formula:
=EXPON(2, 0, 1, "pdf")
Expected output:
0.1353
Example 2: CDF at x=2 with standard exponential
Inputs:
| value | loc | scale | expon_method |
|---|---|---|---|
| 2 | 0 | 1 | cdf |
Excel formula:
=EXPON(2, 0, 1, "cdf")
Expected output:
0.8647
Example 3: Inverse CDF at probability 0.8647
Inputs:
| value | loc | scale | expon_method |
|---|---|---|---|
| 0.8647 | 0 | 1 | icdf |
Excel formula:
=EXPON(0.8647, 0, 1, "icdf")
Expected output:
2.0003
Example 4: Mean of standard exponential distribution
Inputs:
| loc | scale | expon_method |
|---|---|---|
| 0 | 1 | mean |
Excel formula:
=EXPON(0, 1, "mean")
Expected output:
1
Python Code
from scipy.stats import expon as scipy_expon
import math
def expon(value=None, loc=0, scale=1, expon_method='pdf'):
"""
Exponential distribution function wrapping scipy.stats.expon.
See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.expon.html
This example function is provided as-is without any representation of accuracy.
Args:
value (float, optional): Input value for pdf/cdf/sf, or probability for icdf/isf methods Default is None.
loc (float, optional): Location parameter (shift) Default is 0.
scale (float, optional): Scale parameter (must be > 0) Default is 1.
expon_method (str, optional): Distribution method to compute Valid options: PDF, CDF, ICDF, SF, ISF, Mean, Median, Var, Std. Default is 'pdf'.
Returns:
float: Distribution result (float), or error message string.
"""
valid_methods = {'pdf', 'cdf', 'icdf', 'sf', 'isf', 'mean', 'median', 'var', 'std'}
if not isinstance(expon_method, str):
return f"Invalid method: {expon_method}. Must be a string."
method = expon_method.lower()
if method not in valid_methods:
return f"Invalid method: {expon_method}. Must be one of {', '.join(sorted(valid_methods))}."
try:
loc = float(loc)
scale = float(scale)
except (ValueError, TypeError):
return "Invalid input: loc and scale must be numbers."
if scale <= 0:
return "Invalid input: scale must be > 0."
# Methods that require 'value'
if method in {'pdf', 'cdf', 'icdf', 'sf', 'isf'}:
if value is None:
return f"Invalid input: missing required argument 'value' for method '{method}'."
try:
value = float(value)
except (ValueError, TypeError):
return "Invalid input: value must be a number."
if method == 'pdf':
result = scipy_expon.pdf(value, loc=loc, scale=scale)
elif method == 'cdf':
result = scipy_expon.cdf(value, loc=loc, scale=scale)
elif method == 'sf':
result = scipy_expon.sf(value, loc=loc, scale=scale)
elif method == 'icdf':
if not (0 <= value <= 1):
return "Invalid input: value (probability) must be between 0 and 1 for icdf."
result = scipy_expon.ppf(value, loc=loc, scale=scale)
elif method == 'isf':
if not (0 <= value <= 1):
return "Invalid input: value (probability) must be between 0 and 1 for isf."
result = scipy_expon.isf(value, loc=loc, scale=scale)
else:
# Methods that do not require 'value'
if method == 'mean':
result = scipy_expon.mean(loc=loc, scale=scale)
elif method == 'median':
result = scipy_expon.median(loc=loc, scale=scale)
elif method == 'var':
result = scipy_expon.var(loc=loc, scale=scale)
elif method == 'std':
result = scipy_expon.std(loc=loc, scale=scale)
# Handle result
# scipy returns numpy scalars, convert to python float
try:
result = float(result)
except (ValueError, TypeError):
return "Error: Calculation resulted in invalid type."
if math.isnan(result):
return "Result is NaN (not a number)"
if math.isinf(result):
return "inf" if result > 0 else "-inf"
return result